package com.situ.firmadmin.controller;



import com.situ.firmadmin.mapper.OperLogMapper;
import com.situ.firmadmin.pojo.OperLog;
import com.situ.firmadmin.pojo.query.OperLogQuery;
import com.situ.firmadmin.service.IOperLogService;
import com.situ.firmadmin.util.PageResult;
import com.situ.firmadmin.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/operlog")
public class OperLogController {
    @Autowired
    private IOperLogService operLogService;
    
    @GetMapping("/selectNormalByPage")
    public Result normalList(OperLogQuery operLogQuery){
        PageResult pageResult = operLogService.normalList(operLogQuery);
        Map<String, Object> map = new HashMap<>();
        map.put("total",pageResult.getCount());
        map.put("list",pageResult.getData());
        return Result.ok(map);
    }

    @GetMapping("/selectAbnormalByPage")
    public Result abnormalList(OperLogQuery operLogQuery){
        PageResult pageResult = operLogService.abnormalList(operLogQuery);
        Map<String, Object> map = new HashMap<>();
        map.put("total",pageResult.getCount());
        map.put("list",pageResult.getData());
        return Result.ok(map);
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        OperLog operLog=operLogService.selectById(id);
        return Result.ok(operLog);
    }

    @DeleteMapping("/deleteAll/{ids}")
    public Result deleteAll(@PathVariable Integer[] ids){
        operLogService.deleteAll(ids);
        return Result.ok("删除成功！");
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        operLogService.deleteById(id);
        return Result.ok("删除成功！");
    }

    @DeleteMapping("/deleteAllNormal")
    public Result deleteAllNormal(){
        operLogService.deleteAllNormal();
        return Result.ok("清除成功！");
    }
    
    @DeleteMapping("/deleteAllAbnormal")
    public Result deleteAllAbnormal(){
        operLogService.deleteAllAbnormal();
        return Result.ok("清除成功！");
    }
}
